# users.py

from fastapi import APIRouter, Request
from starlette.responses import HTMLResponse, FileResponse
from api.routes.login import get_current_user

router = APIRouter()


@router.post("/test")
def create_user():
    return {"message": "User created successfully"}


@router.get("/index")
async def create_user(request: Request):
    token = request.cookies.get('access_token')
    print(str(token) + "index----")
    try:
        print(await get_current_user(token))
        return FileResponse("webpage/index.html")
    except Exception as e:
        print(e)
        print("error")
        return FileResponse("webpage/loginPage.html")


@router.get("/message_table")
async def create_user(request: Request):
    token = request.cookies.get('access_token')
    print(str(token) + "index----")

    if await get_current_user(token) is not False:
        return FileResponse("webpage/messageTable.html")
    else:
        return FileResponse("webpage/loginPage.html")


@router.get("/login")
def create_user():
    print("login")
    return FileResponse("webpage/loginPage.html")
